package com.sunwayworld.dev.core.db;

import java.sql.Connection;
import java.sql.SQLException;

import com.sunwayworld.dev.core.db.dialect.TableEngine;
import com.sunwayworld.dev.core.db.dialect.TableEngineFactory;
import com.sunwayworld.dev.core.valueobject.Field;
import com.sunwayworld.dev.util.ConnUtil;
import com.sunwayworld.dev.util.StringDevUtil;

public class DBEngine {
	private String tableName = "";

	private Connection conn = null;

	private TableEngine te = null;

	public DBEngine(String tableName) {
		this.tableName = StringDevUtil.toUpperCase(tableName);

	}

	public ColumnModel[] generateColumnModel() throws SQLException {


			te = TableEngineFactory.getInstance(tableName, conn);
			return te.generateColumnModel();


	}

	public TableModel generateTableModel() throws SQLException {

	
			te = TableEngineFactory.getInstance(tableName, conn);
			return te.generateTableModel();
		
	}

	public Field[] getFieldsFromDB() throws SQLException {


			te = TableEngineFactory.getInstance(tableName, conn);
			return te.getFieldsFromDB();

	}

	public Connection openConnection() {
		conn = ConnUtil.getConnection();
		return conn;
	}

	public void closeConnection() {
		ConnUtil.closeConnection(conn, null, null);
	}

}
